#include "host.h"
#include "host_listen_handler.h"

#define DBG_TAG    "host_listen"
#define DBG_LVL    DBG_INFO
#include <rtdbg.h>

typedef void (*Host_Listen_Handler)(rt_uint8_t arg_id, rt_uint16_t arg_value);

Host_Listen_Handler host_listen_handler[] = {
    handler_sv,
    handler_tempAlarmLow,
    handler_tempAlarmHigh,
    handler_at,
    handler_tecCtrlMode,
    handler_tecPower,
    handler_workMode,
    handler_pidKp,
    handler_pidKi,
    handler_pidKd,
    handler_reserve,
    handler_reserve,
    handler_reserve,
    handler_svOffset,
    handler_pvOffset,
    handler_tecOutputDir,
    handler_tempSensorType,
    handler_tempUnit,
    handler_decimalPointNbr,
    handler_displayRangeLow,
    handler_displayRangeHigh,
    handler_filterDegree,
    handler_mbSlaverAddr,
    handler_mbBaudrateID,
    handler_reserve,
    handler_progTimeUnitAdjust,
    handler_progTimeUnitHold,
    handler_progStart,
    handler_progTempAcceptance,
    handler_progStepAdjustTime,
    handler_progStepSv,
    handler_progStepHoldTime,
    handler_progStepMode,
    handler_progStepNextStepNbr,
    handler_progStepLoopCnt,
    handler_progStepAdjustTime,
    handler_progStepSv,
    handler_progStepHoldTime,
    handler_progStepMode,
    handler_progStepNextStepNbr,
    handler_progStepLoopCnt,
    handler_progStepAdjustTime,
    handler_progStepSv,
    handler_progStepHoldTime,
    handler_progStepMode,
    handler_progStepNextStepNbr,
    handler_progStepLoopCnt,
    handler_progStepAdjustTime,
    handler_progStepSv,
    handler_progStepHoldTime,
    handler_progStepMode,
    handler_progStepNextStepNbr,
    handler_progStepLoopCnt,
    handler_progStepAdjustTime,
    handler_progStepSv,
    handler_progStepHoldTime,
    handler_progStepMode,
    handler_progStepNextStepNbr,
    handler_progStepLoopCnt,
    handler_progStepAdjustTime,
    handler_progStepSv,
    handler_progStepHoldTime,
    handler_progStepMode,
    handler_progStepNextStepNbr,
    handler_progStepLoopCnt,
    handler_progStepAdjustTime,
    handler_progStepSv,
    handler_progStepHoldTime,
    handler_progStepMode,
    handler_progStepNextStepNbr,
    handler_progStepLoopCnt,
    handler_progStepAdjustTime,
    handler_progStepSv,
    handler_progStepHoldTime,
    handler_progStepMode,
    handler_progStepNextStepNbr,
    handler_progStepLoopCnt,
    handler_powerOnAutoRun,
    handler_steadyAlarmRange,
    handler_tecMaxPower,
    handler_mbCrcEnable,
    handler_reserve,
    handler_reserve,
    handler_reserve,
    handler_reserve,
    handler_pidMode,
    handler_tempCalibReal,
    handler_tempCalibReal,
    handler_tempCalibReal,
    handler_tempCalibReal,
    handler_tempCalibReal,
    handler_tempCalibReal,
    handler_tempCalibReal,
    handler_tempCalibReal,
    handler_tempCalibReal,
    handler_tempCalibReal,
    handler_tempCalibSet,
    handler_tempCalibSet,
    handler_tempCalibSet,
    handler_tempCalibSet,
    handler_tempCalibSet,
    handler_tempCalibSet,
    handler_tempCalibSet,
    handler_tempCalibSet,
    handler_tempCalibSet,
    handler_tempCalibSet,
    handler_tempCalibPointNbr,
    handler_factory,
};

void host_listen(void)
{
    rt_ssize_t recvState;
    struct Msg_InterThread msg[MSG_MAX_HOST];

    RT_ASSERT(mq_host != RT_NULL); 

    recvState = rt_mq_recv(mq_host, &msg, sizeof(msg), RT_WAITING_NO);
    if(recvState > 0)
    {
        for(rt_uint8_t i = 0; i < recvState / sizeof(msg[0]); i++)
        {
            RT_ASSERT(host_listen_handler[msg[i].arg_id] != RT_NULL);
            host_listen_handler[msg[i].arg_id](msg[i].arg_id, msg[i].arg_value);
        }
    }

}